<style>
  #bottomNotes {
    display: block;
    padding-left: 18px;
    padding-right: 18px;
    padding-bottom: 18px;
  }

  #topPool {
    padding-top: 18px;
    padding-left: 18px;
    padding-right: 18px;
  }

  #topPool>div>div>svg {
    display: block;
    height: 280px;
  }

  .poolWrapper {
    border: solid 1px #c7c7c7;
    border-radius: 5px;
    padding: 5px;
    margin-bottom: 18px;
  }

  .poolLabel {
    font-size: 1.2em;
    text-align: center;
    padding: 4px;
  }

  .poolMinerTable {}

  table {
    width: 100%;
  }
</style>
<div>
  {{ var sortedPools = Object.keys(it.stats.pools); }}
  {{ sortedPools.sort(function(a, b) { return a.workerCount - b.workerCount; }); }}
  <div class="col-md-5 table-responsive">
    <table class="table table-bordered">
      <thead>
        <tr>
          <th><i class="fa fa-history"></i> Block History For</th>
          <th>
            <select class="form-control" id="coinSelect">
              <option class="btn btn-primary dropdown-toggle" value="{{=sortedPools[0]}}" type="button" id="coinDropDown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                {{=sortedPools[0].charAt(0).toUpperCase() + sortedPools[0].slice(1)}}
              </option>
              <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
                {{ for(var i = 1; i < sortedPools.length; i++) { }}
                  <option class="dropdown-item" value="{{=sortedPools[i]}}" type="button">{{=sortedPools[i].charAt(0).toUpperCase() + sortedPools[i].slice(1)}}</button>
                {{ } }}
              </div>
            </div>
          </select>
          </th>
        </tr>
        <tr>
          <th colspan="2" style="text-align: center;">{{=sortedPools[0].charAt(0).toUpperCase() + sortedPools[0].slice(1)}} History</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th><i class="fa fa-hourglass-2"></i> Pending Blocks:</th>
          <td id="tdHistoryPending">{{=it.stats.pools[sortedPools[0]].blocks.pending}}</td>
        </tr>
        <tr>
          <th><i class="fa fa-check"></i> Confirmed Blocks:</th>
          <td id="tdHistoryConfirmed">{{=it.stats.pools[sortedPools[0]].blocks.confirmed}}</td>
        </tr>
      </tbody>
    </table>
  </div>
  <h4 class="display-4 ml-3 mt-0 mb-3" style="font-size: 24px;">Last 50 Confirmed Blocks</h4>
  <fieldset>
  <form action="#" class="form-group" method="post">
  <div class="col-md-12 table-responsive">
    <table id="blockTable" class="table table-bordered table-hover" cellspacing="0">
      <thead>
        <tr>
          <th>Block</th>
          <th>Hash</th>
          <th>Difficulty</th>
          <th>Confirmations</th>
        </tr>
      </thead>
      <tbody id="blockTableBody">
      </tbody>
    </table>
  </div>
  </form>            <!--END OF FORM ^^-->
  </fieldset>
</div>

  <script>

    var dataTable = $("#blockTable").DataTable({
        "order": [[ 0, "desc" ]]
    });

    $("#coinSelect").ready(function() {
      updateTable("{{=Object.keys(it.stats.pools)[0]}}", true);
    });

    $("#coinSelect").change(function() {
      updateTable(this.value, true);
    });

    function updateTable(value, updateText){
      "{{ var sortedPools = Object.keys(it.stats.pools); }}";
      "{{ sortedPools.sort(function(a, b) { return a.workerCount - b.workerCount; }); }}";
      "{{ for(i in sortedPools) { }}";
        "{{ var pool = sortedPools[i]; }}";
        if("{{=pool}}" === value){
          if(updateText){
            $('#tdHistoryPending').text("{{=it.stats.pools[pool].blocks.pending}}");
            $('#tdHistoryConfirmed').text("{{=it.stats.pools[pool].blocks.confirmed}}");
          }
          if(dataTable.row) {
            dataTable.clear().draw();
          }
          var values = [];
          console.log("{{=(it.stats.pools[pool].payments[0] || {}).paid }}");
          if("{{=it.stats.pools[pool].blocks}}" !== 'null'){
            "{{ for(data in it.stats.pools[pool].blocks.confirmedData.slice(0, 50)) { }}";
              if("{{=it.stats.pools[pool].explorer}}" !== 'null'){
                $.getJSON("{{=it.stats.pools[pool].explorerGetBlockJSON}}" + "{{=it.stats.pools[pool].blocks.confirmedData[data]}}".split(':')[0], function(data) {
                  var hash = "{{=it.stats.pools[pool].blocks.confirmedData[data]}}".split(':')[0];
                  dataTable.row.add([
                    data.height,
                    "<a href={{=it.stats.pools[pool].explorerGetBlock}}" + hash + ">" + hash + "</a>",
                    data.difficulty,
                    data.confirmations
                  ]).draw(false);
                });
              }
            "{{ } }}";
            $('#blockTable').dataTable();
          }
        }
      "{{ } }}";
    }
  </script>
